package com.koron.css2.serviceManage.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.serviceManage.bean.BankInterfaceConfigBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.mapper.BankInterfaceConfigMapper;
import com.koron.css2.serviceManage.utils.CommonUtils;
import com.koron.util.Constant;
import com.koron.util.DBSourceUtils;
import com.koron.util.JsonUtils;
import net.sf.json.JSONObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bson.types.ObjectId;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;
/**
 * 添加银行直连配置
 * @author 李攀
 *
 */
public class BankInterfaceConfigAdd implements ServerInterface{
	
	private static Logger logger = LogManager.getLogger(BankInterfaceConfigAdd.class);

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {	
		JSONObject pa=JSONObject.fromObject(req.getData());
		String companyNo=pa.getString("companyNo");//获取参数		
		BankInterfaceConfigMapper mapper = factory.getMapper(BankInterfaceConfigMapper.class,DBSourceUtils.getDbEnv(companyNo));
		BankInterfaceConfigBean bean = new BankInterfaceConfigBean();
		pa.remove("companyNo");//移除参数
		try {
			bean = JsonUtils.objectToPojo(pa, BankInterfaceConfigBean.class);
		} catch (Exception e) {
			logger.error("非法参数", e);
			return MessageBean.create(Constant.ILLEGAL_PARAMETER, "非法参数", void.class);
		}
		bean.setConfigId(new ObjectId().toHexString());
		bean.setCreateName(userInfo.getUserInfo().getName());
		bean.setCreateTime(CommonUtils.getCurrentTime());
		
		mapper.insertBankInterfaceConfig(bean);
		return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", void.class);
	}

}
